﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;
using System.ComponentModel;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using Org.Eurekaa.DNJ.Helpers;

namespace Org.Eurekaa.DNJ.UI.WebControls
{

    [ToolboxBitmap(typeof(Org.Eurekaa.DNJ.UI.Resources.icons.DNJUIIcons), "DNJButtonSet.bmp")]
    [Designer(typeof(Org.Eurekaa.DNJ.UI.Design.WebControls.JQueryUIControlDesigner))]
    //[DefaultProperty("Settings")]    
    [ParseChildren(true)]
    [PersistChildren(false)]

    public class DNJButtonSet : JQueryUIControl
    {
        private List<DNJButton> _buttonset = new List<DNJButton>();

        [Category("$.DNJ Settings")]
        [PersistenceMode(PersistenceMode.InnerProperty)]
        [DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
        [MergableProperty(false)]
        public List<DNJButton> Buttons
        {
            get { return _buttonset; }
            set { _buttonset = value; }
        }
        private HtmlGenericControl _container = new HtmlGenericControl("div");

        //private DNJAutoCompleteSettings _settings = new DNJAutoCompleteSettings();
        //[DefaultValue(""), Category("$.DNJ Settings"), DisplayName("Settings")]
        //[PersistenceMode(PersistenceMode.InnerProperty),
        //DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
        //public DNJAutoCompleteSettings Settings
        //{
        //    get { return _settings; }
        //    set { _settings = value; }
        //}

        //private DNJAutoCompleteEvents _events = new DNJAutoCompleteEvents();
        //[DefaultValue(""), Category("$.DNJ Settings"), DisplayName("Events")]
        //[PersistenceMode(PersistenceMode.InnerProperty),
        //DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
        //public DNJAutoCompleteEvents ClientEvents
        //{
        //    get { return _events; }
        //    set { _events = value; }
        //}



        public override void SaveSettings(ref object stateObject)
        {
            //object[] lstObj = new object[2];
            //lstObj[0] = Settings;
            //lstObj[1] = ClientEvents;

            //stateObject = lstObj;

            //GenericSettingsObject allSettings = new GenericSettingsObject();

            //PageHelper.AppendJQueryScript(ClientEvents.GetDefaultEventsScript(), this.Page.Header);

            //Settings.PrepareJSON();
            //ClientEvents.PrepareJSON();
            //allSettings.Append(Settings);
            //allSettings.Append(ClientEvents);

            PageHelper.AppendJQueryPlugin("#" + _container.ClientID, "buttonset", "", this.Page.Header);

        }


        //public override void LoadSettings(object stateObject)
        //{
        //    object[] lstObj = (object[])stateObject;
        //    Settings = (lstObj[0] as DNJAutoCompleteSettings);
        //    ClientEvents = (lstObj[1] as DNJAutoCompleteEvents);
        //}



        //protected override void Render(HtmlTextWriter writer)
        //{
        //    if (this.DesignMode)
        //    {
        //        _txtBox.Attributes.Add("style", "width:" + this.Width.ToString());
        //        _txtBox.RenderControl(writer);
        //    }
        //    else
        //        base.Render(writer);
        //}

        protected override void CreateChildControls()
        {
            //Controls.Clear();
            _container.ID = "buttonset_" + this.ID;
            if (_buttonset.Count == 0 && DesignMode)
            {
                _container.Attributes.Add("class", "ui-button ui-widget ui-state-default ui-corner-all");
                _container.Attributes.Add("style", "width:100px;height:25px");
                _container.InnerHtml = "<b>Empty set</b>";
            }
            else
            {
                _container.Attributes.Remove("class");
                _container.Attributes.Remove("style");
                _container.InnerHtml = "";
            }

            foreach (DNJButton dnjBtn in Buttons)
            {
                _container.Controls.Add(dnjBtn);
            }
            Controls.Add(_container);

            base.CreateChildControls();

        }
    }


}
